package com.cb.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DelayConfig {

    @Bean
    public Queue queue() {
        return QueueBuilder.durable("booking_queue")
                .withArgument("x-dead-letter-exchange", "booking_dead_exchange")
                .withArgument("x-dead-letter-routing-key", "booking_dead_routing_key")
                .withArgument("x-message-ttl", 60000).build();
    }

    @Bean
    public Exchange exchange() {
        return ExchangeBuilder.directExchange("booking_exchange").durable(true).build();
    }

    @Bean
    public Binding binding() {
        return BindingBuilder.bind(queue()).to(exchange()).with("booking_routing_key").noargs();
    }

    @Bean
    public Exchange deadExchange() {
        return ExchangeBuilder.directExchange("booking_dead_exchange").durable(true).build();
    }

    @Bean
    public Queue deadQueue() {
        return QueueBuilder.durable("booking_dead_queue").build();
    }

    @Bean
    public Binding deadBinding() {
        return BindingBuilder.bind(deadQueue()).to(deadExchange()).with("booking_dead_routing_key").noargs();
    }
}
